package com.niit.TopOne.pctopone;

import com.niit.bean.PcTopOneBean;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class PcTopOneMapper extends Mapper<Object, Text, PcTopOneBean, NullWritable> {
    PcTopOneBean outKey = new PcTopOneBean();
    NullWritable outValue = NullWritable.get();

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        String city = fields[8];
        String school = fields[1];
        String os = fields[2];
        long activeDays = Long.parseLong(fields[10]);

        if (os == null || os.equals("android") || os.equals("ios")||os.equals("")||
                city == null || city.equals("未知") || city.equals("")) {
            return; // 跳过这个记录，不进行处理
        }
            outKey.set(city, school, activeDays);
            context.write(outKey, outValue);

    }
}